﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine;
using PloobsEngine.SceneControl;
using PloobsEngine.Utils;
using Etapa1.SofRender;
using System.Collections.Generic;
using ModelXML;
using PloobsEngine.Cameras;
using Etapa1.Import;
using Etapa1.SofRender.Sample;

namespace Etapa1.Screens
{
    public class SoftGeomScreen : IScreen
    {
        public SoftGeomScreen()
            : base()
        {
        }

        Device device ;
        
        public override void LoadContent(EngineStuff es)
        {
            device = new Device();            
            base.LoadContent(es);
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            device.Clear(Color.Red, 1);

            VertexType v0 = new VertexType();
            VertexType v1 = new VertexType();
            VertexType v2 = new VertexType();
            
            v0[Slots.POSITION0] = new Vector4(-0.5f, -0.5f, 0, 1);
            v1[Slots.POSITION0] = new Vector4(0, 0.5f, 0, 1);
            v2[Slots.POSITION0] = new Vector4(0.5f, -0.5f, 0, 1);
            
            VertexType[] triangle = new VertexType[] { v0, v1, v2};

            ///3 pontos, expandidos em triangulos no gs e pegos no streamout (nao eh realmente necessario o streamout ... ) 
            device.SetEffect(new GeoShaderShader());
            device.SetVertexBuffer(triangle);                        
            device.StreamOut = true;
            device.DrawPrimitive(PrimitivesType.PointList);
            VertexType[] outp;
            outp = device.GetStreamOutBuffer();

            ///desenha os triangulos gerados
            device.SetEffect(new TriangleShader());
            device.SetVertexBuffer(outp);                        
            device.StreamOut = false;
            device.DrawPrimitive(PrimitivesType.TriangleList);        

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void Draw(GameTime gameTime)
        {
            device.Draw();
            base.Draw(gameTime);

        }
    }
        
}

